package com.jifeng.api.crud.controller;

import com.jifeng.api.crud.entity.DeviceEntity;
import com.jifeng.api.crud.service.DeviceService;
import com.jifeng.api.utils.PageUtils;
import com.jifeng.api.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * @author jifeng
 * @email 1593140625@qq.com
 * @date 2020-10-09 19:08:59
 */
@RestController
@RequestMapping("crud/device")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = deviceService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        DeviceEntity device = deviceService.getById(id);

        return R.ok().put("device", device);
    }

    /**
     * 增加设备
     */
    @PostMapping("/pc/add")
    public R addDevice(@RequestBody DeviceEntity device) {
        R rs = deviceService.addDevice(device);

        return rs;
    }

    /**
     * 修改设备
     */
    @PostMapping("/pc/upd")
    public R updDevice(@RequestBody DeviceEntity device) {
        R rs = deviceService.updDevice(device);

        return rs;
    }

    /**
     * 删除设备
     */
    @PostMapping("/pc/del")
    public R delDevice(@RequestBody DeviceEntity device) {
        R rs = deviceService.delDevice(device);
        return rs;
    }

}
